/**
 * Copyright (c) 2016-2019 人人开源 All rights reserved.
 *
 * https://www.qxypt.io
 *
 * 版权所有，侵权必究！
 */

package xw.qxypt.modules.job.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xw.qxypt.modules.baseinfo.entity.LhpRfpDataEntity;
import xw.qxypt.modules.baseinfo.service.LhpRfpDataService;
import xw.qxypt.modules.socket.util.HspUtil;

import java.util.*;

/**
 * 定时存储液位
 *
 * insertLiquidLevelTask为spring bean的名称
 *
 * @author Mark sunlightcs@gmail.com
 */
@Component("insertLiquidLevelTask")
public class InsertLiquidLevelTask implements ITask {
	private Logger logger = LoggerFactory.getLogger(getClass());
	@Autowired
	private LhpRfpDataService lhpRfpDataService;

	@Override
	public void run(String params){

		logger.debug("液位存储定时任务正在执行，参数为：{}", params	);
		HashMap<String, HashMap<String,String>> map= HspUtil.eptMap1;
		List<LhpRfpDataEntity> list=new ArrayList<>();
		for(Map.Entry<String, HashMap<String, String>> en : map.entrySet()) {
			LhpRfpDataEntity lrd = new LhpRfpDataEntity();
			lrd.setDateTime(new Date());
			lrd.setPointCode(en.getKey());
			for(Map.Entry<String,String> e : en.getValue().entrySet()) {
				if(e.getKey().equals("yewei")) {
					lrd.setYewei(e.getValue());
				}
				if(e.getKey().equals("yeya")) {
					lrd.setYeya(e.getValue());
				}
				if(e.getKey().equals("status")) {
					lrd.setStatus(e.getValue());
				}
			}
			list.add(lrd);
		}
		lhpRfpDataService.saveBatch(list);
		map.clear();

	}
}
